﻿/**
 * 插入代码插件
 */
(function(E){
var Consts = E.consts;

E.plugin('Code', {
	inserthtml:'custom',
	config : {
		width: 600,
		position: 'center',
		overlay: true
	},
	langs : {
		'html': 'HTML/XML',
		'js': 'Javascript',
		'css': 'CSS',
		'php': 'PHP',
		'java': 'Java',
		'py': 'Python',
		'pl': 'Perl',
		'rb': 'Ruby',
		'cs': 'C#',
		'c': 'C++/C',
		'vb': 'VB/ASP'
	},
	init : function() {
		var selector = '<select name="code_language" style="margin:2px 0;">';
		for(index in this.langs) {
			selector += '<option value="'+index+'">' + this.langs[index]+'</option>';
		}
		selector +='<option value="">其他</option>';
		selector += '</select>';
		this.cache['html'] = selector+'<textarea value="" name="content" style="width:99%;height:260px"></textarea>';
	},
	check : function(panel, self) {
		var text = panel.find("[name=content]").val();
		if(!text || text.length<1){
			self.error('代码内容不能为空!');
			return false;
		}
		return true;
	},
	get : function(panel, self) {
		var Utils = E.mod("Utils"),
			code_language = panel.find('select[name=code_language]').val(),
			text = panel.find("[name=content]").val();
		text = Utils.escape(text);
		return text = '\n<pre class="prettyprint lang-' + code_language + '">' + text + '</pre>\n';
	}
});

})(jQEditor);